﻿KISSY.add("fgt/ui/popbox", function (S, Overlay) {
    function Popbox(config) {
        this._init(config || {});
    }

    S.augment(Popbox, {
        _init: function (config) {
            var self = this;

            self.config = S.merge(
            {
                content: "<span class='text'></span>",
                contentCls: "text"
            }, config);

            self.box = new Overlay({
                prefixCls: "fgt-pb-",
                content: self.config.content,
                elStyle: { position: S.UA.ie == 6 ? "absolute" : "fixed" },
                closable: false,
                mask: true,
                draggable: false,
                zIndex: 999999
            });
        },

        show: function (text, delay, callback, callbackContext, calllbackParams) {
            var self = this,
                box = self.box;

            box.render();   //must invoke render before get "contentEl"
            if (!self.textNode) {
                self.textNode = box.get("contentEl").all("." + self.config.contentCls);
            }
            self.textNode.text(text || "");
            box.center();
            box.show();

            if (delay) {
                S.later(function () {
                    box.hide();
                    if (callback) {
                        callback.apply(callbackContext || this, calllbackParams || []);
                    }
                }, delay);
            }
            else {
                if (callback) {
                    callback.apply(callbackContext || this, calllbackParams || []);
                }
            }
        },

        hide: function () {
            this.box.hide();
        }
    });

    return Popbox;
}, {
    requires: ["overlay"]
});